package com.chixing.day09_innerclass;

public class StringDemo {
    public static void main(String[] args) {
        String s1 = "hello";
        s1 = "good";
        System.out.println(s1);

        String s2 = new String("code"); //堆
        String s3 = "code";  //字符串常量池
        System.out.println("s2 == s3? :" + (s2 == s3));

        String s4 = "file";
        String s5 = "file";
        System.out.println("s4 == s5? :" + (s4 == s5));  //比较的时内存地址


        System.out.println("=================================");
        /*
        * String s1 = "a";
        * String s2 = "b";
        *  s1+s2 ===> new String("ab") 堆
        *  s1.concat(s2) ===> new String("ab") 堆
        *
        * “a” + "b" ===>在常量池中 放一份“ab”
        * */
        String str11 = "hello";
        String str22 = "world";
        String str33 = str11 + str22;  // new String("helloworld")
        String str44 = "helloworld";
        System.out.println("str33 == str44 ?:" + (str33 == str44)); //false

        String str0 = "hello" + "world";  // "helloworld" 到常量池中匹配
        System.out.println("str0 == str44?:" + (str0 == str44)); // true


        String str55 = str11 + str22;  // new String("helloworld")
        System.out.println("str33 == str55 :" + (str33 == str55));  //false

        String str66 = str11.concat(str22); // new String( "helloworld")
        System.out.println("str3 == str6 :" + (str33 == str66));
    }
}
